namespace DotNetNuke.Services.Exceptions
{
    using DotNetNuke.Entities.Modules;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Runtime.Serialization;
    using System.Security.Permissions;
    using System.Xml.Serialization;

    [Serializable]
    public class ModuleLoadException : BasePortalException
    {
        private string m_FriendlyName;
        private ModuleInfo m_ModuleConfiguration;
        private string m_ModuleControlSource;
        private int m_ModuleDefId;
        private int m_ModuleId;

        public ModuleLoadException()
        {
        }

        public ModuleLoadException(string message) : base(message)
        {
            this.InitilizePrivateVariables();
        }

        protected ModuleLoadException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            this.InitilizePrivateVariables();
            this.m_ModuleId = info.GetInt32("m_ModuleId");
            this.m_ModuleDefId = info.GetInt32("m_ModuleDefId");
            this.m_FriendlyName = info.GetString("m_FriendlyName");
        }

        public ModuleLoadException(string message, Exception inner) : base(message, inner)
        {
            this.InitilizePrivateVariables();
        }

        public ModuleLoadException(string message, Exception inner, ModuleInfo ModuleConfiguration) : base(message, inner)
        {
            this.m_ModuleConfiguration = ModuleConfiguration;
            this.InitilizePrivateVariables();
        }

        [SecurityPermission(SecurityAction.Demand, SerializationFormatter=true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("m_ModuleId", this.m_ModuleId, typeof(int));
            info.AddValue("m_ModuleDefId", this.m_ModuleDefId, typeof(int));
            info.AddValue("m_FriendlyName", this.m_FriendlyName, typeof(string));
            info.AddValue("m_ModuleControlSource", this.m_ModuleControlSource, typeof(string));
            base.GetObjectData(info, context);
        }

        private void InitilizePrivateVariables()
        {
            try
            {
                this.m_ModuleId = this.m_ModuleConfiguration.ModuleID;
                this.m_ModuleDefId = this.m_ModuleConfiguration.ModuleDefID;
                this.m_FriendlyName = this.m_ModuleConfiguration.ModuleTitle;
                this.m_ModuleControlSource = this.m_ModuleConfiguration.ControlSrc;
            }
            catch (Exception exception1)
            {
                
                Exception exc = exception1;
                this.m_ModuleId = -1;
                this.m_ModuleDefId = -1;
                this.m_FriendlyName = "";
                
            }
        }

        [XmlElement("FriendlyName")]
        public string FriendlyName
        {
            get
            {
                return this.m_FriendlyName;
            }
        }

        [XmlElement("ModuleControlSource")]
        public string ModuleControlSource
        {
            get
            {
                return this.m_ModuleControlSource;
            }
        }

        [XmlElement("ModuleDefId")]
        public int ModuleDefId
        {
            get
            {
                return this.m_ModuleDefId;
            }
        }

        [XmlElement("ModuleID")]
        public int ModuleId
        {
            get
            {
                return this.m_ModuleId;
            }
        }
    }
}

